package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.bean.firstpager.AllBrandBean;
import com.eoner.baselibrary.utils.GlideUtil;
import com.eoner.baselibrary.utils.ScreenUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：sean
 * 创建时间：2017/6/15 17:09
 * 功能说明：
 */

public class AllBrandListAdapter extends BaseAdapter {
    public List<AllBrandBean.DataBean.ShBrandsBean> getList() {
        return list;
    }

    public void setList(List<AllBrandBean.DataBean.ShBrandsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    private List<AllBrandBean.DataBean.ShBrandsBean> list;
    private Context context;
    String type;

    public AllBrandListAdapter(Context context,String type) {
        this.context = context;
        this.type = type;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View container, ViewGroup viewGroup) {
        ViewHolder holder;
        if(container == null){
            container = View.inflate(context, R.layout.item_all_brand_2, null);
            holder = new ViewHolder(container);
            container.setTag(holder);
        }else {
            holder = (ViewHolder) container.getTag();
        }
        AllBrandBean.DataBean.ShBrandsBean item = list.get(position);
        if(position == 0){
            holder.tvFirstWord.setText(item.getFirst_word());
            holder.tvFirstWord.setVisibility(View.VISIBLE);
        }else{
            if(!list.get(position-1).getFirst_word().equals(item.getFirst_word())){
                holder.tvFirstWord.setText(item.getFirst_word());
                holder.tvFirstWord.setVisibility(View.VISIBLE);
            }else {
                holder.tvFirstWord.setVisibility(View.GONE);
            }
        }
        if("1".equals(type)){
            holder.tvFirstWord.setBackgroundColor(0xfff5f5f5);
        }
        GlideUtil.displayImage(context,item.getSh_logo(),holder.ivBrandLogo,R.mipmap.defaults,ScreenUtils.dp2px(80),ScreenUtils.dp2px(40));
//        if(!TextUtils.isEmpty(item.getSh_logo())){
//            App.picasso.load(item.getSh_logo()).resize(ScreenUtils.dp2px(80),ScreenUtils.dp2px(40)).into(holder.ivBrandLogo);
//        }
        holder.tvBrandName.setText(item.getSh_name());
        holder.tvBrandDesc.setText(item.getSh_introduce());

        return container;
    }


    static class ViewHolder {
        @BindView(R.id.tv_first_word)
        TextView tvFirstWord;
        @BindView(R.id.iv_brand_logo)
        ImageView ivBrandLogo;
        @BindView(R.id.tv_brand_name)
        TextView tvBrandName;
        @BindView(R.id.tv_brand_desc)
        TextView tvBrandDesc;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
